<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <link rel="stylesheet" th:href="@{/static/element/index.css}"/>
</head>
<body>
<style>
    .el-input-item {
        width: 260px;
    }

</style>
<div id="app">
    <template>
        <el-form :model="formData" ref="formData" :rules="rules" label-width="100px"
                 style="margin-top: 5%;display: flex;flex-direction: row;align-items: center;flex-wrap: wrap;justify-content: space-between;margin-right: 5%">
            <el-form-item label="字典类型" prop="dictTypeId">
                <el-select v-model="formData.dictTypeId" placeholder="请选择" size="small" class="el-input-item">
                    <el-option
                            v-for="item in dictTypeList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="字典排序" prop="dictSort">
                <el-input class="el-input-item" size="small" v-model="formData.dictSort" placeholder="请输入字典排序"/>
            </el-form-item>
            <el-form-item label="字典标签" prop="dictLabel">
                <el-input class="el-input-item" size="small" v-model="formData.dictLabel" placeholder="请输入字典标签"/>
            </el-form-item>
            <el-form-item label="字典键值" prop="dictValue">
                <el-input class="el-input-item" size="small" v-model="formData.dictValue" placeholder="请输入字典键值"/>
            </el-form-item>
        </el-form>
        <div style="text-align: center;margin-top: 5%">
            <el-button size="small" @click="closePage">取 消</el-button>
            <el-button size="small" type="primary" @click="handleSubmit">确 定</el-button>
        </div>
    </template>
</div>
</body>
<script th:src="@{/static/js/axios.min.js}"></script>
<script th:src="@{/static/js/request.js}"></script>
<script th:src="@{/static/js/common.js}"></script>
<script th:src="@{/static/api/sysDictData.js}"></script>
<script th:src="@{/static/js/vue.min.js}"></script>
<script th:src="@{/static/element/index.js}"></script>
<script th:src="@{/static/js/jquery.min.js}"></script>
<script th:src="@{/static/layer/layer.js}"></script>
<script>
    let id = getQueryString("id");
    new Vue({
        el: '#app',
        data() {
            return {
                formData: {
                },
                dictTypeList: [],
                rules: {}
            }
        },
        created() {

            if (id) {
                detail(id).then((res) => {
                    if (res.code === '200') {
                        this.formData = res.data
                        this.formData.dictTypeId = res.data.dictTypeId
                    }
                });
            } else {
                this.formData = {
                    dictTypeId: ""
                }
            }
            this.getDictTypeList()


        },
        methods: {
            getDictTypeList() {
                requests.get("/admin/sysDictType/list").then(res => {
                    if (res.code === '200') {
                        this.dictTypeList = res.data.map(item => {
                            return {
                                label: item.name,
                                value: item.id
                            }
                        })
                    }
                })
            },
            handleSubmit() {
                if (id) {
                    addOrUpdate('/admin/sysDictData/update', this);
                } else {
                    addOrUpdate('/admin/sysDictData/add', this);
                }
            }
        }
    });
</script>
</html>
